import requests
import time
import datetime
import random
from tenacity import retry, stop_after_attempt, wait_fixed

# UP云搜
class upyunso:
    def __init__(self) -> None:
        self.pub_freq = (1*10, 1*60) # 30-60分钟
        # self.pub_freq = (1, 6) # 30-60分钟
        self.last_time = None
        self.header = {
            'sec-ch-ua': '"Chromium";v="110", "Not A(Brand";v="24", "Microsoft Edge";v="110"',
            'user-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36 Edg/110.0.1587.63',
        }
        pass

    @retry(stop=stop_after_attempt(4), wait=wait_fixed(5))
    def share_url(self, link, name = ""):
        while True:
            now = datetime.datetime.now()
            pub_freq_second = random.randint(self.pub_freq[0], self.pub_freq[1])
            if not self.last_time is None and (now-self.last_time).seconds < pub_freq_second:
                time.sleep(10)
            else:
                self.last_time = now
                break

        url = 'https://api.upyunso2.com/submit?s=%s' % (link)
        html = requests.get(url, headers=self.header)
        if html.status_code==200:
            print(link, '发布成功')

    def share_urls(self, links):
        for link in links:
            self.share_url(link)


# 猫狸盘搜
class limaopansou:
    def __init__(self) -> None:
        self.header = {
            'content-type': 'application/x-www-form-urlencoded; charset=UTF-8',
            'sec-ch-ua': '"Chromium";v="110", "Not A(Brand";v="24", "Microsoft Edge";v="110"',
            'user-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36 Edg/110.0.1587.63',
        }
        pass

    @retry(stop=stop_after_attempt(4), wait=wait_fixed(5))
    def share_url(self, link, name = ""):
        url = 'https://alipansou.com/submitRes'
        data= {
            'ticket': 't03QUMR9J7qKIKuJ6P8hw5cCzx6Wo7LhC2tNpXaT-mhSPsD-P_cDyI-G2HWhCyv81EelvG5XpgnVcgLQMcs2auVH1olPaMk0MgEyWhrLKpB08PdJF-oKRe5FBGrlqzgWyVb',
            'randstr': '@DWb',
            'link': link,
            'name': name


        }
        html = requests.get(url, headers=self.header)
        if html.status_code==200:
            print('发布成功')
        else:
            print(html.status_code, html.text)

    def share_urls(self, links):
        for link in links:
            self.share_url(link)


# 
if __name__ == '__main__':
    sharer = limaopansou()
    sharer.share_url('https://www.aliyundrive.com/s/w5wkUwXYnL2')
